Comment about `Clone` on Context
authorAlex Crichton <alex@alexcrichton.com>
Sat, 3 Jun 2017 18:11:22 +0000 (11:11 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 5 Jun 2017 14:36:44 +0000 (07:36 -0700)
src/cargo/core/resolver/mod.rs

index 00b3cdcda7a7ef8a03c7d0ac7708608079091d94..fba3384c284c5aa975a137d8d55e9a388867bc6d 100644 (file)
@@ -295,12 +295,24 @@ enum GraphNode {
     Link(PackageId, PackageId),
 }
 
+// A `Context` is basically a bunch of local resolution information which is
+// kept around for all `BacktrackFrame` instances. As a result, this runs the
+// risk of being cloned *a lot* so we want to make this as cheap to clone as
+// possible.
 #[derive(Clone)]
 struct Context<'a> {
+    // TODO: Both this and the map below are super expensive to clone. We should
+    //       switch to persistent hash maps if we can at some point or otherwise
+    //       make these much cheaper to clone in general.
     activations: Activations,
-    resolve_graph: RcList<GraphNode>,
     resolve_features: HashMap<PackageId, HashSet<String>>,
+
+    // These are two cheaply-cloneable lists (O(1) clone) which are effectively
+    // hash maps but are built up as "construction lists". We'll iterate these
+    // at the very end and actually construct the map that we're making.
+    resolve_graph: RcList<GraphNode>,
     resolve_replacements: RcList<(PackageId, PackageId)>,
+
     replacements: &'a [(PackageIdSpec, Dependency)],
 }